package com.kaibo.roomdemo.data.db

import android.arch.persistence.room.Database
import android.arch.persistence.room.Room
import android.arch.persistence.room.RoomDatabase
import android.arch.persistence.room.TypeConverters
import com.kaibo.roomdemo.App
import com.kaibo.roomdemo.data.db.convert.Converters
import com.kaibo.roomdemo.data.db.dao.BookDao
import com.kaibo.roomdemo.data.db.dao.UserDao
import com.kaibo.roomdemo.data.db.entity.BookEntity
import com.kaibo.roomdemo.data.db.entity.UserEntity

/**
 * @author Administrator
 * @date 2018/2/7 0007 上午 9:44
 * GitHub：
 * email：
 * description：
 */

@TypeConverters(value = [Converters::class])
@Database(entities = [(UserEntity::class), (BookEntity::class)], version = 1)
abstract class RoomDemoDatabase : RoomDatabase() {

    protected abstract fun userDao(): UserDao
    protected abstract fun bookDao(): BookDao

    companion object {
        private val INSTANCE: RoomDemoDatabase by lazy {
            Room.databaseBuilder(App.getInstance(), RoomDemoDatabase::class.java, "RoomDemo.db")
                    .build()
        }

        fun getUserDao() = INSTANCE.userDao()
        fun getBookDao() = INSTANCE.bookDao()

    }
}